package com.vichat.user.entity;


import com.vichat.common.constant.I18nConstant;
import com.vichat.common.exception.ViChatException;
import com.vichat.common.util.StringUtil;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/***************
 *author: autogen
 *version: 2018-10-09 14:02:06.007
 */
@Entity
@Table(name = "user_basic", catalog = "userdb")
public class UserBasic implements java.io.Serializable {

    private static final long serialVersionUID = 1L;


    public static final String TABLE = "user_basic";

    /**
     * 人员ID
     */
    public static final String ALIAS_UID = "uid";
    /**
     * 人员编号
     */
    public static final String ALIAS_USER_NUMBER = "user_number";
    /**
     * 人员姓名
     */
    public static final String ALIAS_USER_NAME = "user_name";
    /**
     * 用户类型 1：超级管理员 2：管理员 3：普通用户
     */
    public static final String ALIAS_USER_TYPE = "user_type";
    /**
     * 性别
     */
    public static final String ALIAS_SEX = "sex";
    /**
     * 头像版本号
     */
    public static final String ALIAS_V_FACE = "v_face";
    /**
     * 设备类型
     */
    public static final String ALIAS_TERMINAL_TYPE = "terminal_type";
    /**
     * 终端设备
     */
    public static final String ALIAS_TERMINAL = "terminal";
    /**
     * 警务通手机
     */
    public static final String ALIAS_PHONE = "phone";
    /**
     * 密码
     */
    public static final String ALIAS_PASSWORD = "password";
    /**
     * 短号码
     */
    public static final String ALIAS_SHORT_NUMBER = "short_number";
    /**
     * IMEI号
     */
    public static final String ALIAS_IMEI = "IMEI";
    /**
     * 是否分配设备 0 已分配 1 未分配
     */
    public static final String ALIAS_ENABLED = "enabled";
    /**
     * 数据 0 无效 1 有效
     */
    public static final String ALIAS_STATE = "state";
    /**
     * 创建时间
     */
    public static final String ALIAS_CREATE_TIME = "create_time";
    /**
     * 修改时间
     */
    public static final String ALIAS_UPDATE_TIME = "update_time";
    /**
     * 版本号
     */
    public static final String ALIAS_VERSION = "version";
    /**
     * 企业编号
     */
    public static final String ALIAS_PARTY_ID = "party_id";
    /**
     * 组织ID
     */
    public static final String ALIAS_ORG_ID = "org_id";
    /**
     * 组织编号
     */
    public static final String ALIAS_ORG_CODE = "org_code";
    /**
     * 0 全组织 1 本组织  2 1级组织 ....
     */
    public static final String ALIAS_VISIBLE = "visible";
    /**
     *
     */
    public static final String ALIAS_DISTRICT_ID = "district_id";
    /**
     *
     */
    public static final String ALIAS_DISTRICT_TYPE = "district_type";
    /**
     * 失效日期
     */
    public static final String ALIAS_EXPIRED_DATE = "expired_date";
    /**
     * ICCID
     */
    public static final String ALIAS_ICCID = "iccid";
    /**
     * APP版本号
     */
    public static final String ALIAS_APP_VERSION = "app_version";
    /**
     *
     */
    public static final String ALIAS_DISPLAY_STATE = "display_state";
    /**
     * 定位开关: 1开 0关
     */
    public static final String ALIAS_LOC_FLAG = "loc_flag";
    /**
     * 定位间隔:秒
     */
    public static final String ALIAS_LOC_INTERVAL = "loc_interval";
    /**
     *
     */
    public static final String ALIAS_MOBILE = "mobile";


    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "uid", unique = true, nullable = false)
    public java.lang.Long uid;

    @Column(name = "user_number")
    public java.lang.String userNumber;

    @Column(name = "user_name")
    public java.lang.String userName;

    @Column(name = "user_type")
    public java.lang.Long userType;

    @Column(name = "sex")
    public java.lang.Long sex;

    @Column(name = "v_face")
    public java.lang.Long vFace = 0l;

    @Column(name = "terminal_type")
    public java.lang.Long terminalType;

    @Column(name = "terminal")
    public java.lang.String terminal;

    @Column(name = "phone")
    public java.lang.String phone;

    @Column(name = "password")
    public java.lang.String password;

    @Column(name = "short_number")
    public java.lang.String shortNumber;

    @Column(name = "IMEI")
    public java.lang.String imei;

    @Column(name = "enabled")
    public java.lang.Long enabled = 0l;

    @Column(name = "state")
    public java.lang.Long state = 1l;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "create_time")
    public java.util.Date createTime;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_time")
    public java.util.Date updateTime;

    @Column(name = "version")
    public java.lang.Long version = 0l;

    @Column(name = "party_id")
    public java.lang.Long partyId;

    @Column(name = "org_id")
    public java.lang.Long orgId;

    @Column(name = "org_code")
    public java.lang.String orgCode;

    @Column(name = "visible")
    public java.lang.Long visible = 0l;

    @Column(name = "district_id")
    public java.lang.Long districtId;

    @Column(name = "district_type")
    public java.lang.Long districtType;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "expired_date")
    public java.util.Date expiredDate;

    @Column(name = "iccid")
    public java.lang.String iccid;

    @Column(name = "app_version")
    public java.lang.String appVersion;

    @Column(name = "display_state")
    public java.lang.Long displayState;

    @Column(name = "loc_flag")
    public java.lang.Long locFlag;

    @Column(name = "loc_interval")
    public java.lang.Long locInterval;

    @Column(name = "mobile")
    public java.lang.String mobile;


    public java.lang.Long getUid() {
        return this.uid;
    }

    public void setUid(java.lang.Long value) {
        this.uid = value;
    }

    public java.lang.String getUserNumber() {
        return this.userNumber;
    }

    public void setUserNumber(java.lang.String value) {
        this.userNumber = value;
    }

    public java.lang.String getUserName() {
        return this.userName;
    }

    public void setUserName(java.lang.String value) {
        this.userName = value;
    }

    public java.lang.Long getUserType() {
        return this.userType;
    }

    public void setUserType(java.lang.Long value) {
        this.userType = value;
    }

    public java.lang.Long getSex() {
        return this.sex;
    }

    public void setSex(java.lang.Long value) {
        this.sex = value;
    }

    public java.lang.Long getVFace() {
        return this.vFace;
    }

    public void setVFace(java.lang.Long value) {
        this.vFace = value;
    }

    public java.lang.Long getTerminalType() {
        return this.terminalType;
    }

    public void setTerminalType(java.lang.Long value) {
        this.terminalType = value;
    }

    public java.lang.String getTerminal() {
        return this.terminal;
    }

    public void setTerminal(java.lang.String value) {
        this.terminal = value;
    }

    public java.lang.String getPhone() {
        return this.phone;
    }

    public void setPhone(java.lang.String value) {
        this.phone = value;
    }

    public java.lang.String getPassword() {
        return this.password;
    }

    public void setPassword(java.lang.String value) {
        this.password = value;
    }

    public java.lang.String getShortNumber() {
        return this.shortNumber;
    }

    public void setShortNumber(java.lang.String value) {
        this.shortNumber = value;
    }

    public java.lang.String getImei() {
        return this.imei;
    }

    public void setImei(java.lang.String value) {
        this.imei = value;
    }

    public java.lang.Long getEnabled() {
        return this.enabled;
    }

    public void setEnabled(java.lang.Long value) {
        this.enabled = value;
    }

    public java.lang.Long getState() {
        return this.state;
    }

    public void setState(java.lang.Long value) {
        this.state = value;
    }

    public java.util.Date getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(java.util.Date value) {
        this.createTime = value;
    }

    public java.util.Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(java.util.Date value) {
        this.updateTime = value;
    }

    public java.lang.Long getVersion() {
        return this.version;
    }

    public void setVersion(java.lang.Long value) {
        this.version = value;
    }

    public java.lang.Long getPartyId() {
        return this.partyId;
    }

    public void setPartyId(java.lang.Long value) {
        this.partyId = value;
    }

    public java.lang.Long getOrgId() {
        return this.orgId;
    }

    public void setOrgId(java.lang.Long value) {
        this.orgId = value;
    }

    public java.lang.String getOrgCode() {
        return this.orgCode;
    }

    public void setOrgCode(java.lang.String value) {
        this.orgCode = value;
    }

    public java.lang.Long getVisible() {
        return this.visible;
    }

    public void setVisible(java.lang.Long value) {
        this.visible = value;
    }

    public java.lang.Long getDistrictId() {
        return this.districtId;
    }

    public void setDistrictId(java.lang.Long value) {
        this.districtId = value;
    }

    public java.lang.Long getDistrictType() {
        return this.districtType;
    }

    public void setDistrictType(java.lang.Long value) {
        this.districtType = value;
    }

    public java.util.Date getExpiredDate() {
        return this.expiredDate;
    }

    public void setExpiredDate(java.util.Date value) {
        this.expiredDate = value;
    }

    public java.lang.String getIccid() {
        return this.iccid;
    }

    public void setIccid(java.lang.String value) {
        this.iccid = value;
    }

    public java.lang.String getAppVersion() {
        return this.appVersion;
    }

    public void setAppVersion(java.lang.String value) {
        this.appVersion = value;
    }

    public java.lang.Long getDisplayState() {
        return this.displayState;
    }

    public void setDisplayState(java.lang.Long value) {
        this.displayState = value;
    }

    public java.lang.Long getLocFlag() {
        return this.locFlag;
    }

    public void setLocFlag(java.lang.Long value) {
        this.locFlag = value;
    }

    public java.lang.Long getLocInterval() {
        return this.locInterval;
    }

    public void setLocInterval(java.lang.Long value) {
        this.locInterval = value;
    }

    public java.lang.String getMobile() {
        return this.mobile;
    }

    public void setMobile(java.lang.String value) {
        this.mobile = value;
    }

    public Long getvFace() {
        return vFace;
    }

    public void setvFace(Long vFace) {
        this.vFace = vFace;
    }


    public UserBasic() {
    }

    public UserBasic(boolean qryflag) {
        if (qryflag) {
            this.uid = null;
            this.userNumber = null;
            this.userName = null;
            this.userType = null;
            this.sex = null;
            this.vFace = null;
            this.terminalType = null;
            this.terminal = null;
            this.phone = null;
            this.password = null;
            this.shortNumber = null;
            this.imei = null;
            this.enabled = null;
            this.state = null;
            this.createTime = null;
            this.updateTime = null;
            this.version = null;
            this.partyId = null;
            this.orgId = null;
            this.orgCode = null;
            this.visible = null;
            this.districtId = null;
            this.districtType = null;
            this.expiredDate = null;
            this.iccid = null;
            this.appVersion = null;
            this.displayState = null;
            this.locFlag = null;
            this.locInterval = null;
            this.mobile = null;
        }
    }


    public UserBasic(
            java.lang.Long inUid,
            java.lang.String inUserNumber,
            java.lang.String inUserName,
            java.lang.Long inUserType,
            java.lang.Long inSex,
            java.lang.Long inVFace,
            java.lang.Long inTerminalType,
            java.lang.String inTerminal,
            java.lang.String inPhone,
            java.lang.String inPassword,
            java.lang.String inShortNumber,
            java.lang.String inImei,
            java.lang.Long inEnabled,
            java.lang.Long inState,
            java.util.Date inCreateTime,
            java.util.Date inUpdateTime,
            java.lang.Long inVersion,
            java.lang.Long inPartyId,
            java.lang.Long inOrgId,
            java.lang.String inOrgCode,
            java.lang.Long inVisible,
            java.lang.Long inDistrictId,
            java.lang.Long inDistrictType,
            java.util.Date inExpiredDate,
            java.lang.String inIccid,
            java.lang.String inAppVersion,
            java.lang.Long inDisplayState,
            java.lang.Long inLocFlag,
            java.lang.Long inLocInterval,
            java.lang.String inMobile
    ) {
        super();
        this.uid = inUid;
        this.userNumber = inUserNumber;
        this.userName = inUserName;
        this.userType = inUserType;
        this.sex = inSex;
        this.vFace = inVFace;
        this.terminalType = inTerminalType;
        this.terminal = inTerminal;
        this.phone = inPhone;
        this.password = inPassword;
        this.shortNumber = inShortNumber;
        this.imei = inImei;
        this.enabled = inEnabled;
        this.state = inState;
        this.createTime = inCreateTime;
        this.updateTime = inUpdateTime;
        this.version = inVersion;
        this.partyId = inPartyId;
        this.orgId = inOrgId;
        this.orgCode = inOrgCode;
        this.visible = inVisible;
        this.districtId = inDistrictId;
        this.districtType = inDistrictType;
        this.expiredDate = inExpiredDate;
        this.iccid = inIccid;
        this.appVersion = inAppVersion;
        this.displayState = inDisplayState;
        this.locFlag = inLocFlag;
        this.locInterval = inLocInterval;
        this.mobile = inMobile;
    }

    @Transient
    private String orgName = "";

    public String getOrgName() {
        return orgName;
    }

    public void setOrgName(String orgName) {
        this.orgName = orgName;
    }

    @Transient
    public String ext1;

    public String getExt1() {
        return ext1;
    }

    public void setExt1(String ext1) {
        this.ext1 = ext1;
    }

    @Transient
    public int isExpried;

    public int getIsExpried() {
        return isExpried;
    }

    public void setIsExpried(int isExpried) {
        this.isExpried = isExpried;
    }

    @Transient
    private Date startDate;
    @Transient
    private Date endDate;

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @Transient
    public String queryUserType;

    public String getQueryUserType() {
        return queryUserType;
    }

    public void setQueryUserType(String queryUserType) {
        this.queryUserType = queryUserType;
    }

    public static String checkUserBasic(UserBasic user) throws ViChatException {
        if (StringUtils.isNotBlank(user.getTerminal())) {
            if (StringUtil.isSpecialChar(user.getTerminal())) {
                return I18nConstant.error_accountSpecialChar;
            }
            if (user.getTerminal().length() > 20) {
                return I18nConstant.error_accountTooLong;
            }
        }
        if (StringUtils.isNotBlank(user.getUserName())) {
//            if (StringUtil.isSpecialChar(user.getUserName())) {
//                return I18nConstant.error_userNameSpecialChar;
//            }
            if (user.getUserName().length() > 100) {
                return I18nConstant.error_userNameTooLong;
            }
        }else{
            return I18nConstant.error_userNameNotEmpty;
        }
        if (StringUtils.isNotBlank(user.getPhone())) {
            if (StringUtil.isSpecialChar(user.getPhone())) {
                return I18nConstant.error_phoneSpecialChar;
            }
            if (user.getPhone().length() > 20) {
                return I18nConstant.error_phoneTooLong;
            }
        }
        if (StringUtils.isNotBlank(user.getImei())) {
            if (StringUtil.isSpecialChar(user.getImei())) {
                user.setTerminal(user.getImei());
                return I18nConstant.error_imeiSpecialChar;
            }
            if (user.getImei().length() > 30) {
                user.setTerminal(user.getImei());
                return I18nConstant.error_imeiTooLong;
            }
        }else{
            return I18nConstant.error_IMEINotEmpty;
        }
        return null;
    }

    @Transient
    private List<Long> roids;

    public List<Long> getRoids() {
        return roids;
    }

    public void setRoids(List<Long> roids) {
        this.roids = roids;
    }
}

